{template "content","header"}
<div class="ui-header">
		<a href="{APP_PATH}" id="icoback" class="header-btn left-pos">返回</a>
		<h1 class="ui-title">爱车盟</h1>
	</div>
	<div id="wrapper">
		
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=581ac4a0ece7eca5b38005d04d1d14f2"></script>
		

		<div id="map" style="width: 100%;height: 100%;overflow: hidden;margin:0;"></div>
<script type="text/javascript">
//  标注点数组
var adds = [
<?php
$review = pc_base::load_model('review_model');
 if(is_array($data)) {
	foreach ($data as $r) {		
	
	$r['position'] =  explode("|", $r['position']);
	
	$intro ='';
	$stat =  $review->query('SELECT avg(good) FROM v9_review WHERE shop_id ='.$r['userid']);
	$stat=mysql_fetch_assoc($stat);
	
	$minprice =  $review->query('SELECT price FROM v9_good WHERE shop_id ='.$r['userid'].' order by price ASC limit 1');
	$minprice=mysql_fetch_assoc($minprice);
	
	$maxprice =  $review->query('SELECT price FROM v9_good WHERE shop_id ='.$r['userid'].' order by price DESC limit 1');
	$maxprice=mysql_fetch_assoc($maxprice);
	
	if($minprice){
	 $intro = '<br /> 评价: '.intval($stat['avg(good)']).'星    消费: '.$minprice[price].'元 - '.$maxprice[price].'元';
	}
	
	$outdata .= '{title:"'.$r['name'].'",content:"地址: '.$r['address'].' '.$intro.'",id:"'.$r['userid'].'",point:"'.$r['position'][1].'|'.$r['position'][0].'",isOpen:0,icon:{w:21,h:21,l:115,t:46,x:1,lb:10}},';
 }
}
	$outdata = substr($outdata,0,strlen($outdata)-1);
	echo $outdata;
?>]


//创建和初始化地图函数：
function atmark_map(){
    window.map = new BMap.Map("map");
	map.centerAndZoom("佛山",15);
	var point = new BMap.Point({$aa['content']['point']['x']}, {$aa['content']['point']['y']});  // 创建点坐标  
	map.centerAndZoom(point, 14);
	//map.centerAndZoom("佛山", 14);
    map.enableScrollWheelZoom();
	map.addControl(new BMap.NavigationControl());
    addMarker(adds);//向地图中添加marker
}

//创建marker
window.addMarker = function (data){
   // map.clearOverlays();
    for(var i=0;i<data.length;i++){
        var json = data[i];
        var p0 = json.point.split("|")[0];
        var p1 = json.point.split("|")[1];
        var point = new BMap.Point(p0,p1);
		var myIcon = new BMap.Icon("{IMG_PATH}location.gif", new BMap.Size(17,16));
        var marker = new BMap.Marker(point,{icon:myIcon});
        var iw = createInfoWindow(i);
        var label = new BMap.Label(json.title,{"offset":new BMap.Size(json.icon.lb-json.icon.x+10,-20)});
        marker.setLabel(label);
        map.addOverlay(marker);


		(function(){
		var _json = json;
		var _iw = createInfoWindow(_json);
		var _marker = marker;
		_marker.addEventListener("click",function(){
			this.openInfoWindow(_iw);
		   });
		   _iw.addEventListener("open",function(){
			_marker.getLabel().hide();
		   })
		   _iw.addEventListener("close",function(){
			_marker.getLabel().show();
		   })
		label.addEventListener("click",function(){
			_marker.openInfoWindow(_iw);
		   })
		if(!!json.isOpen){
		 label.hide();
		 _marker.openInfoWindow(_iw);
		}
		})()
    }
}
//创建InfoWindow
function createInfoWindow(json){
  var iw = new BMap.InfoWindow("<b class='iw_poi_title' title='" + json.title + "'>" + json.title + "</b><div class='iw_poi_content'>"+json.content+"<br /><a href='{APP_PATH}index.php?m=content&c=shop&a=content&id="+json.id+"' style='font-size:14px;font-weight:bold;color:blue'>点击查看详细</a></div>");
  return iw;
}

atmark_map();
</script>
	</div>
	
{template "content","footer"}
</div>